package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.abel533.echarts.style.ItemStyle;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ImageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.domain.ReportSource;
import com.ruoyi.generator.service.IGenWordService;
import com.ruoyi.generator.util.SpireDocUtils;
import com.ruoyi.generator.util.WordUtils;
import com.ruoyi.system.domain.PoPublicOpinion;
import com.ruoyi.system.domain.PublicOpinionEvents;
import com.ruoyi.system.domain.PublicOpinionReport;
import com.ruoyi.system.domain.ReportElement;
import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.enums.ArticleStyleEnum;
import com.ruoyi.system.service.IBriefReportService;
import com.ruoyi.system.service.IGenerateReportService;
import com.ruoyi.system.service.IPoPublicOpinionService;
import com.ruoyi.system.service.IPublicOpinionEventsService;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

@Service
public class GenerateReportServiceImpl implements IGenerateReportService {
    @Autowired
    private IPublicOpinionEventsService opinionEventsService;
    @Autowired
    private IPoPublicOpinionService publicOpinionService;
    @Autowired
    private IGenWordService genWordService;
    @Autowired
    private IBriefReportService briefReportService;
    @Autowired
    private PublicOpinionReportServiceImpl publicOpinionReportService;
    @Value("${phantomjs.savePath}")
    private String phantomjsSavePath;
    @Value("${ruoyi.profile}")
    private String ruoyiProfile;
    @Autowired
    private IPublicOpinionEventsService publicOpinionEventsService;
    @Autowired
    private EsUtil esUtil;
    @Autowired
    private IGenerateReportService generateReportService;

    @Override
    public String getBriefingGuide(Long eventId) {
        //获取事件对象
        PublicOpinionEvents event = opinionEventsService.selectPublicOpinionEventsById(eventId);
        //当前日期
        Date currDate = DateUtils.getCurrentDate();
        //事件结束日期
        Date startDate = event.getStartTime();
        //事件结束日期
        Date endDate = event.getEndTime();
        //确定计算的结束日期
        endDate = endDate.getTime() >= currDate.getTime() ? currDate : endDate;
        //获取各类信息总数
        String des = "根据对各大媒体新闻报道的跟进监测，现对根据对各大媒体新闻报道的跟进监测，现对" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate) + "至" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate) + "重要舆情进行汇总，谨供参阅";
        return des;
    }

    @Override
    public String getSuggestions(Long eventId) {
        return "对于舆情信息中具有潜在危害的事件及情况应给予关注并积极处理，防止不良影响产生及扩散。此外，密切关注此前敏感预警事件的发展情况，及时制定有效应对措施。鉴于监测结果中负面舆情时有发生， 应吸取相关经验教训，做好预防和处理工作。";
    }

    @Override
    public String getMonitoringOverview(Long eventId) {
        String des = "监测主题相关信息内容0条。";
        DecimalFormat df = new DecimalFormat("0.00");
        OpTypeNumVM opTypeDaysNum = publicOpinionService.getTypeNumEvent(eventId, null, null);
        if (opTypeDaysNum.getAllNum() != 0) {
            des = "监测主题相关信息内容" + opTypeDaysNum.getAllNum() + "条。其中" +
                    "正面" + opTypeDaysNum.getPositive() +
                    "条，正面占比" + (df.format(((float) opTypeDaysNum.getPositive() / opTypeDaysNum.getAllNum()) * 100)) + "%，" +
                    "中性" + opTypeDaysNum.getNeutral() +
                    "条，中性占比" + (df.format(((float) opTypeDaysNum.getNeutral() / opTypeDaysNum.getAllNum()) * 100)) + "%，" +
                    "负面" + opTypeDaysNum.getNegative() +
                    "条，负面占比" + (df.format(((float) opTypeDaysNum.getNegative() / opTypeDaysNum.getAllNum()) * 100)) + "%。";
        }
        return des;
    }

    @Override
    public String getEventOverview(Long eventId) {
        //获取事件对象
        PublicOpinionEvents event = opinionEventsService.selectPublicOpinionEventsById(eventId);
        //当前日期
        Date currDate = DateUtils.getCurrentDate();
        //事件结束日期
        Date startDate = event.getStartTime();
        //事件结束日期
        Date endDate = event.getEndTime();
        //确定计算的结束日期
        endDate = endDate.getTime() >= currDate.getTime() ? currDate : endDate;
        //绑定的舆情
        List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);

        //获取各类信息总数
        List<NameValue> values = publicOpinionService.getMediaNameNum(eventId, null, bindIds);

        long counts = publicOpinionService.getAllOpinionCount(event, null, bindIds);

        StringBuffer sbName = new StringBuffer();
        int indexMax = 0;
        int valueMax = 0;
        for (int i = 0; i < values.size(); i++) {
            if (1 == 0) {
                sbName.append(values.get(i).getName());
            } else {
                sbName.append("、" + values.get(i).getName());
            }
            //判断影响力最大的媒体
            if (values.get(i).getValue() > valueMax) {
                indexMax = i;
                valueMax = values.get(i).getValue();
            }
        }

        String des = "本报告针对" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate) +
                "至" +
                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate) +
                "时间范围内，互联网上的相关舆论数据进行了分析。文章分析关键词包括" + event.getRelatedWords() +
                "。在分析时间范围内，共有" + counts +
                "篇相关文章。舆论主要集中在境内，主要来源于" + sbName.toString() +
                "等几大网站，" + values.get(indexMax).getName() +
                "类型的相关舆论最多。详细报告如下：";
        return des;
    }


    @Override
    public String getBriefingOverview(Long eventId) {
        List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);
        List<NameValue> values = publicOpinionService.getMediaNameNum(eventId, null, bindIds);
        String des = "本报告就相关的文章进行分析，共有0篇相关素材。";
        int sum = 0;
        StringBuffer sbName = new StringBuffer();
        StringBuffer sbMax = new StringBuffer();
        StringBuffer sbPercentage = new StringBuffer();
        int indexMax = 0;
        int valueMax = 0;
        sbName.append("目前主要的报道集中在");
        for (int i = 0; i < values.size(); i++) {
            sum += values.get(i).getValue();
            if (1 == 0) {
                sbName.append(values.get(i).getName());
            } else {
                sbName.append("、" + values.get(i).getName());
            }
            //判断影响力最大的媒体
            if (values.get(i).getValue() > valueMax) {
                indexMax = i;
                valueMax = values.get(i).getValue();
            }
        }
        sbPercentage.append("其中");
        DecimalFormat df = new DecimalFormat("0.00");
        for (int i = 0; i < values.size(); i++) {
            String pe = df.format((float) values.get(i).getValue() / sum * 100);
            sbPercentage.append(values.get(i).getName() + values.get(i).getValue() + "篇，" + "占比" + pe + "%，");
        }

        if (sum > 0) {
            sbMax.append("而" + values.get(indexMax).getName() + "的比重最大，共有" + values.get(indexMax).getValue() + "篇，达到信息总量的" + df.format(((float) values.get(indexMax).getValue() / sum) * 100) + "%。");
            sbName.append("等媒体，");
            des = "本报告就相关的文章进行分析，共有" + sum + "篇相关素材。" +
                    sbName.toString() +
                    sbPercentage.toString() +
                    sbMax.toString() +
                    "详细报告请继续浏览";
        }
        return des;
    }

    @Override
    public Map<String, Object> getInformationTrend(Long eventId) {
        //获取事件对象
        PublicOpinionEvents event = opinionEventsService.selectPublicOpinionEventsById(eventId);
        //绑定的舆情
        List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);

        //当前日期
        Date currDate = DateUtils.getCurrentDate();
        //事件结束日期
        Date startDate = event.getStartTime();
        //事件结束日期
        Date endDate = event.getEndTime();
        //确定计算的结束日期
        endDate = endDate.getTime() >= currDate.getTime() ? currDate : endDate;
        //取日期集合
        List<String> dateList = DateUtils.getDatesBetweenUsingJava7String(startDate, endDate);
        //信息趋势图
        List<NameValue> informationTrend = publicOpinionService.getCountGroupByPublishDate(eventId, null, bindIds);

        //获取缩放区间
        double dataZoomStart = getDataZoomStart(dateList, informationTrend);
        double dataZoomEnd = getDataZoomEnd(dateList, informationTrend);

        BigDecimal startB = new BigDecimal(dataZoomStart);
        double start = startB.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
        BigDecimal endB = new BigDecimal(dataZoomEnd);
        double end = endB.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();


        Map<String, Object> map = new HashMap<>();
        map.put("dateList", dateList);
        map.put("dataZoomStart", start);
        map.put("dataZoomEnd", end);
        map.put("informationTrend", informationTrend);//信息趋势
        return map;
    }

    private JSONArray getEventDevelopmentStage(List<String> dateList, List<NameValue> informationTrend) {
        ItemStyle itemStyleRed = new ItemStyle();
        itemStyleRed.setColor("rgba(245,108,108, 0.4)");

        ItemStyle itemStyleGreen = new ItemStyle();
        itemStyleGreen.setColor("rgba(103,194,58, 0.4)");

        ItemStyle itemStyleBlue = new ItemStyle();
        itemStyleBlue.setColor("rgba(64,158,255, 0.4)");

        ItemStyle itemStyleOrange = new ItemStyle();
        itemStyleOrange.setColor("rgba(230,162,60, 0.4)");

        if (informationTrend.size() == 1) {
            List<NameXAxis> fazhan = new ArrayList<>();
            List<NameXAxis> shuaitui = new ArrayList<>();
            for (int i = 0; i < dateList.size(); i++) {
                if (dateList.get(i).equals(informationTrend.get(0).getName())) {
                    if (dateList.size() > 1) {
                        NameXAxis xAxis = new NameXAxis();
                        xAxis.setName("发展期");
                        xAxis.setXAxis(dateList.get(i - 1));
                        xAxis.setItemStyle(itemStyleBlue);
                        fazhan.add(xAxis);

                        xAxis = new NameXAxis();
                        xAxis.setName("发展期");
                        xAxis.setItemStyle(itemStyleBlue);
                        xAxis.setXAxis(dateList.get(i));
                        fazhan.add(xAxis);
                    }
                    if ((i + 1) < dateList.size()) {
                        NameXAxis xAxis = new NameXAxis();
                        xAxis.setName("衰退期");
                        xAxis.setXAxis(dateList.get(i));
                        xAxis.setItemStyle(itemStyleOrange);
                        shuaitui.add(xAxis);

                        xAxis = new NameXAxis();
                        xAxis.setName("衰退期");
                        xAxis.setItemStyle(itemStyleOrange);
                        xAxis.setXAxis(dateList.get(i + 1));
                        shuaitui.add(xAxis);
                    }
                }
            }
            List<List<NameXAxis>> datas = new ArrayList<>();
            datas.add(fazhan);
            datas.add(shuaitui);
            JSONArray array = JSONArray.parseArray(JSON.toJSONString(datas));
            return array;
        } else if (informationTrend.size() == 2) {

            if (informationTrend.get(0).getValue() < informationTrend.get(1).getValue()) {
                List<NameXAxis> mengya = new ArrayList<>();
                List<NameXAxis> fazhan = new ArrayList<>();
                List<NameXAxis> shuaitui = new ArrayList<>();
                for (int i = 0; i < dateList.size(); i++) {
                    if (dateList.get(i).equals(informationTrend.get(0).getName())) {
                        if (dateList.size() > 1) {
                            NameXAxis xAxis = new NameXAxis();
                            xAxis.setName("形成期");
                            xAxis.setXAxis(dateList.get(i - 1));
                            xAxis.setItemStyle(itemStyleGreen);
                            mengya.add(xAxis);

                            xAxis = new NameXAxis();
                            xAxis.setName("形成期");
                            xAxis.setItemStyle(itemStyleGreen);
                            xAxis.setXAxis(dateList.get(i));
                            mengya.add(xAxis);
                        }

                    }

                    if (dateList.get(i).equals(informationTrend.get(1).getName())) {
                        if (dateList.size() > 1) {
                            NameXAxis xAxis = new NameXAxis();
                            xAxis.setName("发展期");
                            xAxis.setXAxis(dateList.get(i - 1));
                            xAxis.setItemStyle(itemStyleBlue);
                            fazhan.add(xAxis);

                            xAxis = new NameXAxis();
                            xAxis.setName("发展期");
                            xAxis.setXAxis(dateList.get(i));
                            xAxis.setItemStyle(itemStyleBlue);
                            fazhan.add(xAxis);
                        }
                        if ((i + 1) < dateList.size()) {
                            NameXAxis xAxis = new NameXAxis();
                            xAxis.setName("衰退期");
                            xAxis.setXAxis(dateList.get(i));
                            xAxis.setItemStyle(itemStyleOrange);
                            shuaitui.add(xAxis);

                            xAxis = new NameXAxis();
                            xAxis.setName("衰退期");
                            xAxis.setXAxis(dateList.get(i + 1));
                            xAxis.setItemStyle(itemStyleOrange);
                            shuaitui.add(xAxis);
                        }
                    }
                }
                List<List<NameXAxis>> datas = new ArrayList<>();
                datas.add(mengya);
                datas.add(fazhan);
                datas.add(shuaitui);
                JSONArray array = JSONArray.parseArray(JSON.toJSONString(datas));
                return array;


            } else {

            }

        } else if (informationTrend.size() > 2) {
            List<NameXAxis> xingcheng = new ArrayList<>();
            List<NameXAxis> fazhan = new ArrayList<>();
            List<NameXAxis> baofa = new ArrayList<>();
            List<NameXAxis> shuaitui = new ArrayList<>();
            List<List<NameXAxis>> datas = new ArrayList<>();


            double sum = 0;
            for (NameValue item : informationTrend) {
                sum += item.getValue();
            }

            double n = 0;
            String xAxisXingcheng = null;
            String xAxisFazhan = null;
            for (int i = 0; i < informationTrend.size(); i++) {
                n += informationTrend.get(i).getValue();
                if (n / sum < 0.2) {
                    xAxisXingcheng = informationTrend.get(i).getName();
                }
                if (n / sum < 0.4) {
                    xAxisFazhan = informationTrend.get(i).getName();
                }
            }

            if (StringUtils.isNotEmpty(xAxisXingcheng)) {
                NameXAxis xAxis = new NameXAxis();
                xAxis.setName("形成期");
                xAxis.setXAxis(informationTrend.get(0).getName());
                xAxis.setItemStyle(itemStyleGreen);
                xingcheng.add(xAxis);

                xAxis = new NameXAxis();
                xAxis.setName("形成期");
                xAxis.setXAxis(xAxisXingcheng);
                xAxis.setItemStyle(itemStyleGreen);
                xingcheng.add(xAxis);
                datas.add(xingcheng);

                if (StringUtils.isNotEmpty(xAxisFazhan)) {
                    xAxis = new NameXAxis();
                    xAxis.setName("发展期");
                    xAxis.setXAxis(xAxisXingcheng);
                    xAxis.setItemStyle(itemStyleBlue);
                    fazhan.add(xAxis);

                    xAxis = new NameXAxis();
                    xAxis.setName("发展期");
                    xAxis.setXAxis(xAxisFazhan);
                    xAxis.setItemStyle(itemStyleBlue);
                    fazhan.add(xAxis);
                    datas.add(fazhan);
                }
            }


            int maxValueIndex = 0;
            for (int i = 0; i < informationTrend.size(); i++) {
                if (informationTrend.get(i).getValue() > informationTrend.get(maxValueIndex).getValue()) {
                    maxValueIndex = i;
                }
            }
            String maxValueName = informationTrend.get(maxValueIndex).getName();
            NameXAxis xAxis = new NameXAxis();
            xAxis.setName("衰退期");
            xAxis.setXAxis(maxValueName);
            xAxis.setItemStyle(itemStyleOrange);
            shuaitui.add(xAxis);

            xAxis = new NameXAxis();
            xAxis.setName("衰退期");
            xAxis.setXAxis(dateList.get(dateList.size() - 1));
            xAxis.setItemStyle(itemStyleOrange);
            shuaitui.add(xAxis);

            datas.add(shuaitui);

            if (StringUtils.isNotEmpty(xAxisFazhan)) {
                xAxis = new NameXAxis();
                xAxis.setName("爆发期");
                xAxis.setXAxis(xAxisFazhan);
                xAxis.setItemStyle(itemStyleRed);
                baofa.add(xAxis);

                xAxis = new NameXAxis();
                xAxis.setName("爆发期");
                xAxis.setXAxis(maxValueName);
                xAxis.setItemStyle(itemStyleRed);
                baofa.add(xAxis);
                datas.add(baofa);
            }


            JSONArray array = JSONArray.parseArray(JSON.toJSONString(datas));

            return array;
        }
        return null;

    }

    private double getDataZoomEnd(List<String> dateList, List<NameValue> informationTrend) {
        double dataZoomEnd = 100.0;
        for (int i = 0; i < dateList.size(); i++) {
            for (NameValue nameValue : informationTrend) {
                if (nameValue.getValue() != 0 && dateList.get(i).equals(nameValue.getName())) {
                    dataZoomEnd = (i + 2) * 100.0 / dateList.size();
                    break;
                }
            }
        }
        ;
        return dataZoomEnd;
    }

    private double getDataZoomStart(List<String> dateList, List<NameValue> informationTrend) {
        double dataZoomStart = 0.0;
        for (int i = 0; i < dateList.size(); i++) {
            if (dataZoomStart == 0.0) {
                for (NameValue nameValue : informationTrend) {
                    if (nameValue.getValue() != 0 && dateList.get(i).equals(nameValue.getName())) {
                        dataZoomStart = i * 100.0 / dateList.size();
                        break;
                    }
                }
            }
        }
        ;
        return dataZoomStart;
    }


    @Override
    public List<NameValue> getMediaNameAnalysis(Long eventId) {
        List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);
        //媒体来源明细
        List<NameValue> mediaSourceDetails = publicOpinionService.getMediaNameNum(eventId, null, bindIds);
        return mediaSourceDetails;

    }

    @Override
    public List<NameValue> getMediaTypeAnalysis(Long eventId) {
        //来源类型分析
        List<NameValue> sourceTypeAnalysis = publicOpinionService.getMediaTypeNum(eventId, null, null);
        return sourceTypeAnalysis;
    }


    @Override
    public OpTypeNumVM getEmotionDistribution(Long eventId) {
        //信息情感分布
        OpTypeNumVM informationEmotionDistribution = publicOpinionService.getTypeNumEvent(eventId, null, null);
        return informationEmotionDistribution;
    }

    @Override
    public List<PoPublicOpinion> getStartingMedia(Long eventId) {
        //绑定的舆情
        List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);
        List<PoPublicOpinion> opinions = publicOpinionService.getStartingMedia(eventId, null, bindIds);
        return opinions;
    }


    @Override
    public Map<String, Object> getMediaNameTrend(Long eventId, String timeType, String beginPublishDay, String endPublishDay) {
        if (StringUtils.isNotEmpty(timeType) || StringUtils.isNotEmpty(beginPublishDay) || StringUtils.isNotEmpty(endPublishDay)) {
            HashMap hashMap = DateUtils.getStartEndTime(timeType, beginPublishDay, endPublishDay);
            beginPublishDay = (String) hashMap.get("beginPublishDay");
            endPublishDay = (String) hashMap.get("endPublishDay");
        }
        //媒体传播分析
        List<NameListValue> linkedHashMap = publicOpinionService.getCountsByPublishDayMediaName(eventId, beginPublishDay, endPublishDay);
        Map<String, Object> map = new HashMap<>();
        map.put("linkedHashMap", linkedHashMap);//信息趋势
        return map;
    }

    @Override
    public String generateReportByManual(Long eventId, List<ReportElement> elements) {
        List<ReportSource> contents = new ArrayList<>();
        //获取事件对象
        PublicOpinionEvents event = opinionEventsService.selectPublicOpinionEventsById(eventId);
        BriefReportVo template = briefReportService.getDefaultTemplate();
        //取报告信息
        elements.forEach(ele -> {
            //段落标题
            String paragraphTitle = ele.getShowName() != null ? ele.getShowName() : ele.getName();

            if (StringUtils.isNotEmpty(ele.getType())) {
                if (StringUtils.isNotEmpty(ele.getRes()) && ele.getType().equals("1")) {
                    //统计信息
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setText(ele.getRes());
                    contents.add(source);
                } else if (ele.getName().equals("文本") && ele.getType().equals("3")) {
                    //文本
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setText(ele.getText());
                    contents.add(source);
                }
            } else if (StringUtils.isNotEmpty(ele.getRes())) {
                //统计图
                String[] imageString = ele.getRes().split(",");
                if (imageString.length == 2) {
                    String imageBase64 = imageString[1];
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(ImageUtils.GenerateImagePath(imageBase64, phantomjsSavePath, null));
                    ImageUtils.base64StrToFile(imageBase64, phantomjsSavePath + eventId + "\\", paragraphTitle + ".jpg");
                    contents.add(source);
                }
            } else {
                if (ele.getName().equals("主要舆情")) {
                    List<PoPublicOpinion> opinions = publicOpinionEventsService.getMainPublicOpinion(eventId, 20);
                    List<HashMap<String, String>> list = new ArrayList<>();
                    for (int i = 0; i < opinions.size(); i++) {
                        String sensitive = "";
                        if (opinions.get(i).getIspositive() == 1) {
                            sensitive = "正面";
                        } else if (opinions.get(i).getIsneutral() == 1) {
                            sensitive = "中性";
                        } else if (opinions.get(i).getIsnegative() == 1) {
                            sensitive = "负面";
                        }
                        HashMap<String, String> map = new HashMap<>();
                        map.put("序号", String.valueOf(i + 1));
                        String title = getTitleOpinion(opinions.get(i));
                        map.put("标题", title + "\n" + (opinions.get(i).getUrl() != null ? opinions.get(i).getUrl() : ""));
                        String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                        String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                        map.put("日期与来源", date + "\n" + source);
                        map.put("属性", sensitive);

                        list.add(map);
                    }
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setTable(list);
                    source.setStyle(ArticleStyleEnum.MainPublicOpinion.value);
                    contents.add(source);
                } else if (ele.getName().equals("舆情导读")) {
                    List<PoPublicOpinion> opinions = publicOpinionEventsService.getGuideToReadingPublicOpinion(eventId, 20);
                    List<HashMap<String, String>> list = new ArrayList<>();
                    for (int i = 0; i < opinions.size(); i++) {
                        String sensitive = "";
                        if (opinions.get(i).getIspositive() == 1) {
                            sensitive = "正面";
                        } else if (opinions.get(i).getIsneutral() == 1) {
                            sensitive = "中性";
                        } else if (opinions.get(i).getIsnegative() == 1) {
                            sensitive = "负面";
                        }
                        HashMap<String, String> map = new HashMap<>();
                        map.put("序号", String.valueOf(i + 1));
                        map.put("属性", sensitive);
                        String title = getTitleOpinion(opinions.get(i));
                        map.put("标题", title);
                        String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                        map.put("来源", source);
                        map.put("链接", opinions.get(i).getUrl() != null ? opinions.get(i).getUrl() : "");
                        String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                        map.put("日期", date);
                        map.put("内容", opinions.get(i).getSummary());
                        list.add(map);
                    }
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setTable(list);
                    source.setStyle(ArticleStyleEnum.PublicOpinionGuide.value);
                    contents.add(source);
                } else if (ele.getName().equals("事件脉络")) {
                    List<PoPublicOpinion> opinions = publicOpinionService.selectPoPublicOpinionListEventId(eventId);
                    List<HashMap<String, String>> list = new ArrayList<>();
                    for (int i = 0; i < opinions.size(); i++) {
                        HashMap<String, String> map = new HashMap<>();
                        map.put("序号", String.valueOf(i + 1));
                        String title = getTitleOpinion(opinions.get(i));
                        map.put("标题", title);
                        String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                        map.put("来源", source);
                        String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                        map.put("日期", date);
                        map.put("内容", opinions.get(i).getTitle());
                        list.add(map);
                    }
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setTable(list);
                    source.setStyle(ArticleStyleEnum.VenationOfTheEvent.value);
                    contents.add(source);
                } else if (ele.getName().equals("热门文章")) {
                    PageInfo<PoPublicOpinion> pageInfo = publicOpinionService.hotPublicOpinion(eventId, null, null, 10, 1, null);
                    List<PoPublicOpinion> opinions = pageInfo.getList();
                    List<HashMap<String, String>> list = new ArrayList<>();
                    for (int i = 0; i < opinions.size(); i++) {
                        HashMap<String, String> map = new HashMap<>();
                        map.put("序号", String.valueOf(i + 1));
                        String title = getTitleOpinion(opinions.get(i));
                        map.put("标题", title);
                        String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                        map.put("来源", source);
                        String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                        map.put("日期", date);
                        map.put("内容", opinions.get(i).getTitle());
                        list.add(map);
                    }
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setTable(list);
                    source.setStyle(ArticleStyleEnum.VenationOfTheEvent.value);
                    contents.add(source);
                } else if (ele.getName().equals("首发媒体溯源")) {
                    //绑定的舆情
                    List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);
                    List<PoPublicOpinion> opinions = publicOpinionService.getStartingMedia(eventId, null, bindIds);
                    List<HashMap<String, String>> list = new ArrayList<>();
                    for (int i = 0; i < opinions.size(); i++) {
                        HashMap<String, String> map = new HashMap<>();
                        map.put("媒体类型", opinions.get(i).getMediaType());
                        String title = getTitleOpinion(opinions.get(i));
                        map.put("标题", title);
                        String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                        map.put("发布时间", date);
                        String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                        map.put("信息来源", source);
                        list.add(map);
                    }
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setTable(list);
                    source.setStyle(ArticleStyleEnum.StartingMediaTracing.value);
                    contents.add(source);
                }


            }


        });

        String path = genWordService.genWord(
                contents,
                event.getEventTitle() + "事件报告",
                template.getFontFamily(),
                template.getFontFamilyTitle(),
                template.getFontFamilyTitleSecond(),
                template.getFontWeight(),
                template.getFontWeightTitle(),
                template.getFontWeightTitleSecond(),
                template.getPublishingDepartment(),
                template.getFontSizeTitle(),
                template.getFontSizeParagraph(),
                template.getFontSizeContent(),
                event.getEventTitle(),
                template.getFontTitleColor(),
                template.getStyle(),
                event.getStartTime(),
                event.getEndTime()
        );

        PublicOpinionReport report = new PublicOpinionReport();
        report.setName(event.getEventTitle() + "简报");
        report.setStatus(0);
        report.setTemplateName(template.getTemplateName());
        //定期报告需要设置type
//        report.setType(type);
        report.setUrlWord(path);
        report.setEventId(eventId);
        try {
            report.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
            report.setTenantCode(SecurityUtils.getLoginUser().getUser().getTenantCode());
            report.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
            report.setCreateName(SecurityUtils.getLoginUser().getUser().getNickName());
        } catch (CustomException e) {
            //定时任务无法获取到UserId
            report.setUserId(0L);
            report.setCreateName("系统");
        }
        int res=publicOpinionReportService.insertPublicOpinionReport(report);
        if (res > 0) {
            // 创建一个线程对象，并将耗时任务对象作为参数传入
            Thread thread = new Thread(() -> generateReportService.wordToPdfByReportId(report.getId()));
            // 开启线程
            thread.start();
        }
        return path;
    }

    /**
     * 从舆情里获取标题
     *
     * @param opinion
     * @return
     */

    String getTitleOpinion(PoPublicOpinion opinion) {
        String title;
        if (StringUtils.isNotEmpty(opinion.getContent())) {
            if (opinion.getContent().length() > 50) {
                title = opinion.getContent().substring(0, 50);
            } else {
                title = opinion.getContent();
            }
        } else {
            if (opinion.getTitle().length() > 50) {
                title = opinion.getTitle().substring(0, 50);
            } else {
                title = opinion.getTitle();
            }
        }
        return title;
    }

    @Override
    public void generateReportByTimedExecution(Long eventId, Long templateId, String type) {
        List<ReportSource> contents = new ArrayList<>();
        //获取事件对象
        PublicOpinionEvents event = opinionEventsService.selectPublicOpinionEventsById(eventId);
        BriefReportVo template = briefReportService.selectBriefReportById(templateId);

        //取报告信息
        template.getElements().forEach(reportElement -> {
            //段落标题
            String paragraphTitle = reportElement.getShowName() != null ? reportElement.getShowName() : reportElement.getName();


            if (reportElement.getName().equals("监测概述")) {
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setText(getMonitoringOverview(eventId));
                contents.add(source);

            } else if (reportElement.getName().equals("事件简介")) {
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setText(getEventOverview(eventId));
                contents.add(source);

            } else if (reportElement.getName().equals("本期导读")) {
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setText(getBriefingGuide(eventId));
                contents.add(source);

            } else if (reportElement.getName().equals("简报概述")) {
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setText(getBriefingOverview(eventId));
                contents.add(source);
            } else if (reportElement.getName().equals("处置建议")) {
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setText(reportElement.getShowText());
                contents.add(source);
            } else if (reportElement.getName().equals("高频词云")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("来源类型分析")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("信息情感分布")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("载体情感分析")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("媒体来源明细")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("信息走势图")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("情感分析")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("媒体传播分析")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("信息载体趋势")) {
                String path = phantomjsSavePath + eventId + "\\" + paragraphTitle + ".jpg";
                if (ImageUtils.isFileExists(path)) {
                    ReportSource source = new ReportSource();
                    source.setTitle(paragraphTitle);
                    source.setImagePath(path);
                    contents.add(source);
                }
            } else if (reportElement.getName().equals("主要舆情")) {
                List<PoPublicOpinion> opinions = publicOpinionEventsService.getMainPublicOpinion(event.getEventId(), 20);
                List<HashMap<String, String>> list = new ArrayList<>();
                for (int i = 0; i < opinions.size(); i++) {
                    String sensitive = "";
                    if (opinions.get(i).getIspositive() == 1) {
                        sensitive = "正面";
                    } else if (opinions.get(i).getIsneutral() == 1) {
                        sensitive = "中性";
                    } else if (opinions.get(i).getIsnegative() == 1) {
                        sensitive = "负面";
                    }
                    HashMap<String, String> map = new HashMap<>();
                    map.put("序号", String.valueOf(i + 1));
                    String title;
                    if (opinions.get(i).getTitle().length() > 50) {
                        title = opinions.get(i).getTitle().substring(0, 50);
                    } else {
                        title = opinions.get(i).getTitle();
                    }
                    map.put("标题", title + "\n" + (opinions.get(i).getUrl() != null ? opinions.get(i).getUrl() : ""));
                    String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                    String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                    map.put("日期与来源", date + "\n" + source);
                    map.put("属性", sensitive);

                    list.add(map);
                }
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setTable(list);
                source.setStyle(ArticleStyleEnum.MainPublicOpinion.value);
                contents.add(source);
            } else if (reportElement.getName().equals("舆情导读")) {
                List<PoPublicOpinion> opinions = publicOpinionEventsService.getGuideToReadingPublicOpinion(event.getEventId(), 20);
                List<HashMap<String, String>> list = new ArrayList<>();
                for (int i = 0; i < opinions.size(); i++) {
                    String sensitive = "";
                    if (opinions.get(i).getIspositive() == 1) {
                        sensitive = "正面";
                    } else if (opinions.get(i).getIsneutral() == 1) {
                        sensitive = "中性";
                    } else if (opinions.get(i).getIsnegative() == 1) {
                        sensitive = "负面";
                    }
                    HashMap<String, String> map = new HashMap<>();
                    map.put("序号", String.valueOf(i + 1));
                    map.put("属性", sensitive);
                    String title;
                    if (opinions.get(i).getTitle().length() > 50) {
                        title = opinions.get(i).getTitle().substring(0, 50);
                    } else {
                        title = opinions.get(i).getTitle();
                    }
                    map.put("标题", title);
                    String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                    map.put("来源", source);
                    map.put("链接", opinions.get(i).getUrl() != null ? opinions.get(i).getUrl() : "");
                    String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                    map.put("日期", date);
                    map.put("内容", opinions.get(i).getSummary());
                    list.add(map);
                }
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setTable(list);
                source.setStyle(ArticleStyleEnum.PublicOpinionGuide.value);
                contents.add(source);
            } else if (reportElement.getName().equals("事件脉络")) {
                List<PoPublicOpinion> opinions = publicOpinionService.selectPoPublicOpinionListEventId(event.getEventId());
                List<HashMap<String, String>> list = new ArrayList<>();
                for (int i = 0; i < opinions.size(); i++) {
                    HashMap<String, String> map = new HashMap<>();
                    map.put("序号", String.valueOf(i + 1));
                    String title;
                    if (opinions.get(i).getContent().length() > 50) {
                        title = opinions.get(i).getContent().substring(0, 50);
                    } else {
                        title = opinions.get(i).getContent();
                    }
                    map.put("标题", title);
                    String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                    map.put("来源", source);
                    String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                    map.put("日期", date);
                    map.put("内容", opinions.get(i).getTitle());
                    list.add(map);
                }
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setTable(list);
                source.setStyle(ArticleStyleEnum.VenationOfTheEvent.value);
                contents.add(source);
            } else if (reportElement.getName().equals("热门文章")) {
                PageInfo<PoPublicOpinion> pageInfo = publicOpinionService.hotPublicOpinion(event.getEventId(), null, null, 10, 1, null);
                List<PoPublicOpinion> opinions = pageInfo.getList();
                List<HashMap<String, String>> list = new ArrayList<>();
                for (int i = 0; i < opinions.size(); i++) {
                    HashMap<String, String> map = new HashMap<>();
                    map.put("序号", String.valueOf(i + 1));
                    String title;
                    if (opinions.get(i).getContent().length() > 50) {
                        title = opinions.get(i).getContent().substring(0, 50);
                    } else {
                        title = opinions.get(i).getContent();
                    }
                    map.put("标题", title);
                    String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                    map.put("来源", source);
                    String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                    map.put("日期", date);
                    map.put("内容", opinions.get(i).getTitle());
                    list.add(map);
                }
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setTable(list);
                source.setStyle(ArticleStyleEnum.VenationOfTheEvent.value);
                contents.add(source);
            } else if (reportElement.getName().equals("首发媒体溯源")) {
                //绑定的舆情
                List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);
                List<PoPublicOpinion> opinions = publicOpinionService.getStartingMedia(event.getEventId(), null, bindIds);
                List<HashMap<String, String>> list = new ArrayList<>();
                for (int i = 0; i < opinions.size(); i++) {
                    HashMap<String, String> map = new HashMap<>();
                    map.put("媒体类型", opinions.get(i).getMediaType());
                    String title;
                    if (opinions.get(i).getContent().length() > 50) {
                        title = opinions.get(i).getContent().substring(0, 50);
                    } else {
                        title = opinions.get(i).getContent();
                    }
                    map.put("标题", title);
                    String date = opinions.get(i).getPublishTime() != null ? DateUtils.parseDateToStr("yyyy-MM-dd", opinions.get(i).getPublishTime()) : opinions.get(i).getPublishDay();
                    map.put("发布时间", date);
                    String source = StringUtils.isNotEmpty(opinions.get(i).getMediaName()) ? opinions.get(i).getMediaName() : (StringUtils.isNotEmpty(opinions.get(i).getAuthor()) ? opinions.get(i).getAuthor() : opinions.get(i).getMediaType());
                    map.put("信息来源", source);
                    list.add(map);
                }
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setTable(list);
                source.setStyle(ArticleStyleEnum.StartingMediaTracing.value);
                contents.add(source);
            } else if (reportElement.getName().equals("文本")) {
                ReportSource source = new ReportSource();
                source.setTitle(paragraphTitle);
                source.setText(reportElement.getText());
                contents.add(source);
            }


        });

        String path = genWordService.genWord(
                contents,
                event.getEventTitle() + "事件报告",
                template.getFontFamily(),
                template.getFontFamilyTitle(),
                template.getFontFamilyTitleSecond(),
                template.getFontWeight(),
                template.getFontWeightTitle(),
                template.getFontWeightTitleSecond(),
                template.getPublishingDepartment(),
                template.getFontSizeTitle(),
                template.getFontSizeParagraph(),
                template.getFontSizeContent(),
                event.getEventTitle(),
                template.getFontTitleColor(),
                template.getStyle(),
                event.getStartTime(),
                event.getEndTime()
        );

        PublicOpinionReport report = new PublicOpinionReport();
        if (StringUtils.isNotEmpty(type)) {
            //定期报告需要设置type
            report.setType(type);
            if (type.equals("day")) {
                report.setName(event.getEventTitle() + "日报");
            } else if (type.equals("week")) {
                report.setName(event.getEventTitle() + "周报");
            } else if (type.equals("month")) {
                report.setName(event.getEventTitle() + "月报");
            }
        } else {
            report.setName(event.getEventTitle() + "简报");
        }

        report.setStatus(0);
        report.setTemplateName(template.getTemplateName());
        report.setUrlWord(path);
        report.setEventId(eventId);
        try {
            report.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
            report.setCreateName(SecurityUtils.getLoginUser().getUser().getNickName());
        } catch (CustomException e) {
            //定时任务无法获取到UserId
            report.setUserId(0L);
            report.setCreateName("系统");
        }
        int res = publicOpinionReportService.insertPublicOpinionReport(report);

        if (res > 0) {
            // 创建一个线程对象，并将耗时任务对象作为参数传入
            Thread thread = new Thread(() -> wordToPdfByReportId(report.getId()));
            // 开启线程
            thread.start();
        }


    }

    @Override
    public Map<String, Object> getEventStage(Long eventId) {
        //获取事件对象
        PublicOpinionEvents event = opinionEventsService.selectPublicOpinionEventsById(eventId);
        //绑定的舆情
        List<String> bindIds = publicOpinionEventsService.getMatchOpinionByEventIdForDataBase(eventId);

        //当前日期
        Date currDate = DateUtils.getCurrentDate();
        //事件结束日期
        Date startDate = event.getStartTime();
        //事件结束日期
        Date endDate = event.getEndTime();
        //确定计算的结束日期
        endDate = endDate.getTime() >= currDate.getTime() ? currDate : endDate;
        //取日期集合
        List<String> dateList = DateUtils.getDatesBetweenUsingJava7String(startDate, endDate);


        List<String> dateListForecast = null;
        if (endDate.getTime() >= currDate.getTime()) {
            dateListForecast = DateUtils.getDatesBetweenUsingJava7String(DateUtils.LocalDateToUdate(DateUtils.dateAfterToday(1)), DateUtils.LocalDateToUdate(DateUtils.dateAfterToday(7)));
        }

        //信息趋势图
        List<NameValue> informationTrend = publicOpinionService.getCountGroupByPublishDate(eventId, null, bindIds);

        //获取缩放区间
        double dataZoomStart = getDataZoomStart(dateList, informationTrend);
        double dataZoomEnd = getDataZoomEnd(dateList, informationTrend);

        BigDecimal startB = new BigDecimal(dataZoomStart);
        double start = startB.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
        BigDecimal endB = new BigDecimal(dataZoomEnd);
        double end = endB.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();

        JSONArray markAreaData = getEventDevelopmentStage(dateList, informationTrend);


        Map<String, Object> map = new HashMap<>();
        map.put("dateList", dateList);
        map.put("dateListForecast", dateListForecast);
        map.put("dataZoomStart", start);
        map.put("dataZoomEnd", end);
        map.put("markAreaData", markAreaData);
        map.put("informationTrend", informationTrend);//信息趋势
        return map;
    }

    /**
     * 将指定报告id的报告doc转成pdf
     *
     * @param reportId
     * @return
     */

    @Override
    public int wordToPdfByReportId(Long reportId) {
        PublicOpinionReport report = publicOpinionReportService.selectPublicOpinionReportById(reportId);
        String docName = report.getUrlWord();
        String pdfName = docName.replace("docx", "pdf");
        String pdfPath = SpireDocUtils.Word2Pdf(ruoyiProfile + "/" +report.getUrlWord(), ruoyiProfile + "/" + pdfName);
        if (StringUtils.isNotEmpty(pdfPath)) {
            report.setUrlPdf(pdfName);
            return publicOpinionReportService.updatePublicOpinionReport(report);
        }
        return 0;
    }
}
